//
//  TableViewController.m
//  UI_13_AutoLayOut强化
//
//  Created by li cheng on 16/8/1.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "TableViewController.h"
#import "MyTableViewCell.h"
#import "SelfSizeTool.h"

@interface TableViewController ()
@property (nonatomic, strong) NSArray *array;

@end

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.array = [NSArray arrayWithObjects:@"去年4月的一次国务院常务会议上，李克强总理针对一些中介评估乱象表示，现在要建一个项目，评估环节包括环评、水评、能评、震评、交评、雷评、气评等，“都被人编成了笑话”!", @"这段话在网络上引发热议，更推动了防雷减灾领域一场持续至今的改革。中国气象局当即召开全国气象部门电视电话会，明确提出各级气象部门立即取消“雷评”中介服务事项。两个月后，中国气象局宣布将“防雷装置设计技术评价”和“新建、改建、扩建建(构)筑物防雷装置检测”两项服务改由气象部门委托有关机构开展，不再向行政相对人收取费用，“雷电灾害风险评估”、“防雷产品测试”两项行政审批中介服务事项则彻底成为“历史”。" , @"到今年3月底，涉及防雷行政审批的所有中介服务全部清理规范完毕，‘红顶中介’问题得到有效解决。”中国气象局有关负责人介绍，“这一改革不仅给企业带来了便利，更彻底切断了中介服务的利益关联，铲除了腐败土壤。", nil];
    // 预估高度
    self.tableView.estimatedRowHeight = 300;
    // 自动计算高度
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    // 2.根据label内容,计算高度,并赋予tableView
    // 好处,可以存贮高度,可以省去部分计算的时间
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = [SelfSizeTool selfSizeHeightWithString:_array[indexPath.row] width:[UIScreen mainScreen].bounds.size.width font:[UIFont systemFontOfSize:17]];
    return height + 0.5f;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    cell.MyLabel.text = _array[indexPath.row];
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
